package com.yunhe.rentcars.pro.service.client.impl;

import com.yunhe.rentcars.commons.annoaction.Log;
import com.yunhe.rentcars.commons.dto.Pageable;
import com.yunhe.rentcars.pro.dao.client.ClientUserDao;
import com.yunhe.rentcars.pro.entity.client.ClientCompany;
import com.yunhe.rentcars.pro.entity.client.ClientUser;
import com.yunhe.rentcars.pro.service.client.ClientUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/11/23 0023.
 */
@Service
public class ClientUserserviceImpl implements ClientUserService {
    @Autowired
     private ClientUserDao clientUserDao;
    @Override
    public Pageable<ClientUser> findPage(Integer offset,Integer limit) {
        List<ClientUser> list = clientUserDao.findPage(offset,limit);
        int count = clientUserDao.count();
        Pageable<ClientUser> pageable=new Pageable<>();
        pageable.setRows(list);
        pageable.setTotal(count);
        return pageable;
    }

    @Override
    @Log(value = "添加客户信息",type = 1)
    public Long save(ClientUser clientUser, ClientCompany clienCompany) {
        clientUserDao.saveCompany(clienCompany);
        clientUser.setCompanyId(clienCompany.getId());
        clientUserDao.save(clientUser);
        return clientUser.getUid();

    }

    @Override
    @Log(value = "删除客户信息",type = 2)
    public void delBatch(String[] ids) {
        clientUserDao.delBatch(ids);
    }

    @Override
    public ClientUser find(Long uId) {
        ClientUser clientUser = clientUserDao.find(uId);
        return clientUser;
    }

    @Override
    @Log(value = "修改客户信息",type = 3)
    public void update(ClientUser clientUser) {
        clientUserDao.update(clientUser);
    }

    @Override
    public Pageable<ClientUser> findSearchList(String memLevel, Date startTime, Date endTime) {
        List<ClientUser> searchList = clientUserDao.findSearchList(memLevel, startTime, endTime);
        Pageable<ClientUser> pageable=new Pageable<>();
        int count = clientUserDao.count();
        pageable.setRows(searchList);
        pageable.setTotal(count);
        return pageable;
    }

    @Override
    public void saveCompany(ClientCompany clientCompany) {

    }
}
